<?php
mysql_set_charset('utf8');
$id=$_POST['id'];
$password=$_POST['password'];
$nickname=$_POST['nickname'];
$confirm=$_POST['confirm'];

$dbh = new PDO('mysql:dbname=orb;host=localhost', 'root', '');

$sql = "SELECT UserName FROM Accounts WHERE UserName='$id'";
$array=$dbh->query($sql);

$resultSet=$array->fetchAll();
$resultNum=count($resultSet);

if($resultNum>0)
{
	header("Location: http://hacksteam-a.dnuts.jp/createnew.php");
	exit(1);
}

$length=strlen($id);
if($length<5&&$length>10)
{
	header("Location: http://hacksteam-a.dnuts.jp/createnew.php");
	exit(1);
}

$length=strlen($password);
if($length<8&&$length>12)
{
	header("Location: http://hacksteam-a.dnuts.jp/createnew.php");
	exit(1);
}

$length=mb_strlen($nickname);
echo $length;
if($length<2&&$length>15)
{
	header("Location: http://hacksteam-a.dnuts.jp/createnew.php");
	exit(1);
}

if($password!=$confirm)
{
	header("Location: http://hacksteam-a.dnuts.jp/createnew.php");
	exit(1);
}

$prep = $dbh->prepare('INSERT INTO Accounts(username,password,point,nickname,profilepicture) VALUES(:username,:password,:point,:nickname,:profilepicture)');
$prep->bindValue(':username',$id,PDO::PARAM_STR);
$prep->bindValue(':password',$password,PDO::PARAM_STR);
$prep->bindValue(':nickname',$nickname,PDO::PARAM_STR);
$prep->bindValue(':point',0,PDO::PARAM_INT);
$prep->bindValue(':profilepicture',"default.png",PDO::PARAM_STR);
$prep->execute();

// MySQLに対する処理

header("Location: http://hacksteam-a.dnuts.jp/index.php");
$dbh=null;
?>